package ren.nearby.http.moduledi;

import android.app.Activity;
import android.app.Application;
import android.content.Context;
import android.util.Log;

import com.orhanobut.logger.AndroidLogAdapter;
import com.orhanobut.logger.FormatStrategy;
import com.orhanobut.logger.Logger;
import com.orhanobut.logger.PrettyFormatStrategy;

import javax.inject.Inject;

import dagger.android.AndroidInjector;
import dagger.android.DispatchingAndroidInjector;
import dagger.android.HasActivityInjector;

/**
 * Created by Administrator on 2018/5/4 0004.
 */

public class BaseApplication extends Application implements HasActivityInjector {
    @Inject
    DispatchingAndroidInjector<Activity> dispatchingAndroidInjector;

    @Override
    public AndroidInjector<Activity> activityInjector() {
        return dispatchingAndroidInjector;
    }

    BaseApplication baseApplication;

    public BaseApplication getBaseApplication() {
        return baseApplication;
    }

    private static DiComponent diComponent;

    public DiComponent getDiModuleComponent() {
        return diComponent;
    }

    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        Log.e("rent","attachBaseContext");
//        https://blog.csdn.net/javazejian/article/details/73413292
        applicationDelegate = new ApplicationDelegate();
        applicationDelegate.attachBaseContext(base);

    }

    @Override
    public void onCreate() {
        super.onCreate();
        initLog();
        baseApplication = this;
//        diComponent =
//                DaggerDiComponent
//                        .builder()
//                        .httpModule3(new HttpModule3(this, 0))
//                        .build();
//        applicationDelegate.onCreate(this, diComponent);
    }

    public void inject(BaseApplication baseApplication) {
//        diModuleComponent.inject(baseApplication);
    }

    /**
     * 初始化输出日志配置
     */
    public void initLog() {
        FormatStrategy formatStrategy = PrettyFormatStrategy
                .newBuilder()
                .showThreadInfo(true)
//                .methodCount(5)
//                .methodOffset(7)
//                .logStrategy()
                .tag("rent")
                .build();
        Logger.addLogAdapter(new AndroidLogAdapter(formatStrategy));
    }

    private ApplicationDelegate applicationDelegate;


}
